package com.csjbot.weedle_auto.fragment

import android.content.Context
import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.csjbot.weedle_auto.util.SharePreferenceTools

/**
 * Created by chenqi on 8/4/17.
 */

@Suppress("UNREACHABLE_CODE")
abstract class BaseFramgent : Fragment(), ActivityCompat.OnRequestPermissionsResultCallback {

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = LayoutInflater.from(activity).inflate(
                resureID, null)
        val parent = view!! as ViewGroup
        parent.removeView(view)
        sharePreferenceTools = SharePreferenceTools(activity)
        initView(view)
        view.isSaveEnabled = false
        return view
    }


    override fun onStart() {
        super.onStart()
    }

    override fun onAttach(context: Context?) {
        super.onAttach(context)
    }

    override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        super.setUserVisibleHint(isVisibleToUser)
        if (userVisibleHint) {
            inVisible()
        } else {
            unInVisible()
        }
    }

    private fun inVisible() {}
    private fun unInVisible() {}
    abstract val resureID: Int

    override fun onDestroyView() {
        super.onDestroyView()
    }


    protected open fun initView(view: View) {}


    companion object {
        lateinit var sharePreferenceTools: SharePreferenceTools
    }

}
